package com.ruoyi.game.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.game.domain.GameReplay;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.game.service.IGameReplayService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 牌局回放Controller
 * 
 * @author ruoyi
 * @date 2025-04-18
 */
@RestController
@RequestMapping("/game/replay")
public class GameReplayController extends BaseController
{
    @Autowired
    private IGameReplayService gameReplayService;

    /**
     * 获取指定牌谱（前端接口）
     */
    @GetMapping("/set/{setId}/replay")
    public AjaxResult getReplayBySetId(@PathVariable("setId") Long setId) {
        // TODO: 从数据库中根据 setId 查询牌谱
        // 示例结构：
        // GameReplay replay = gameReplayService.selectGameReplayBySetId(setId);
        // return success(replay);

        Map<String, Object> data = new HashMap<>();
        data.put("setId", setId);
        data.put("replay", "TODO: 返回对应 setId 的牌谱数据");

        return success(data);
    }

    /**
     * 查询牌局回放列表
     */
    // @PreAuthorize("@ss.hasPermi('game:replay:list')")
    @GetMapping("/list")
    public TableDataInfo list(GameReplay gameReplay)
    {
        startPage();
        List<GameReplay> list = gameReplayService.selectGameReplayList(gameReplay);
        return getDataTable(list);
    }

    /**
     * 导出牌局回放列表
     */
    // @PreAuthorize("@ss.hasPermi('game:replay:export')")
    @Log(title = "牌局回放", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GameReplay gameReplay)
    {
        List<GameReplay> list = gameReplayService.selectGameReplayList(gameReplay);
        ExcelUtil<GameReplay> util = new ExcelUtil<GameReplay>(GameReplay.class);
        util.exportExcel(response, list, "牌局回放数据");
    }

    /**
     * 获取牌局回放详细信息
     */
    // @PreAuthorize("@ss.hasPermi('game:replay:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gameReplayService.selectGameReplayById(id));
    }

    /**
     * 新增牌局回放
     */
    // @PreAuthorize("@ss.hasPermi('game:replay:add')")
    @Log(title = "牌局回放", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GameReplay gameReplay)
    {
        return toAjax(gameReplayService.insertGameReplay(gameReplay));
    }

    /**
     * 修改牌局回放
     */
    // @PreAuthorize("@ss.hasPermi('game:replay:edit')")
    @Log(title = "牌局回放", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GameReplay gameReplay)
    {
        return toAjax(gameReplayService.updateGameReplay(gameReplay));
    }

    /**
     * 删除牌局回放
     */
    // @PreAuthorize("@ss.hasPermi('game:replay:remove')")
    @Log(title = "牌局回放", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gameReplayService.deleteGameReplayByIds(ids));
    }
}
